package com.vanzo.some;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.nfc.Tag;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

import java.net.SocketTimeoutException;

/**
 * Created by tisen on 2017/8/24.
 */

public class NetworkReceiver extends BroadcastReceiver {
    public static final String SHARED_PREFERENCES = "service";
    public static final String SHARED_LAST_TIME = "last_time";
    public static final long timeInterval = 600 * 1000;
    private long lastTime;
    private long timeStamp;

    @Override
    public void onReceive(final Context context, Intent intent) {
        if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
            final SharedPreferences.Editor editor = preferences.edit();
            ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = manager.getActiveNetworkInfo();
            if (networkInfo != null && networkInfo.isConnected()) {
                if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    String model = "vanzo_nx18_k16";
                    boolean status = false;
                    lastTime = preferences.getLong(SHARED_LAST_TIME, 0);
                    timeStamp = System.currentTimeMillis();
                    if (timeStamp - lastTime > timeInterval) {

                    } else {

                    }

                } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {

                }
            }
        }
    }

}





































